package zhtt.parameter;

import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.*;

/**
 * Created by ztt on 2018/5/19.
 */
public class DeptTest {

    private SqlSession sqlSession=null;

    @Test
    public void save01(){
        Dept dept=new Dept("boy");
        int r=sqlSession.insert("zhtt.parameter.DeptMapper.save01",dept);
        System.out.println(r);
        sqlSession.commit();
    }

    @Test
    public void save02(){
        Map<String,Object> map= new HashMap<String,Object>();
        map.put("deptName","lily");
        map.put("createTime",new Date());
        int r=sqlSession.insert("zhtt.parameter.DeptMapper.save02",map);
        System.out.println(r);
        sqlSession.commit();
    }

    @Test
    public void save03(){
        List<Dept> deptList=new ArrayList<Dept>();
        for(int i=0;i<3;i++){
            deptList.add(new Dept("boy"+i));
        }
        int r=sqlSession.insert("zhtt.parameter.DeptMapper.save03",deptList);
        System.out.println(r);
        sqlSession.commit();
    }

    @Test
    public void query01(){
        int result=sqlSession.selectOne("zhtt.parameter.DeptMapper.query01");
        System.out.printf("result：%d\n",result);
    }

    @Test
    public void query02(){
        String result=sqlSession.selectOne("zhtt.parameter.DeptMapper.query02",1);
        System.out.printf("result：%s\n",result);
    }

    @Test
    public void query03(){
        Map<String,Object> result=sqlSession.selectOne("zhtt.parameter.DeptMapper.query03",1);
        System.out.println("result：%s\n"+result);
    }

    @Test
    public void query04(){
        List<String> result=sqlSession.selectList("zhtt.parameter.DeptMapper.query04","b");
        System.out.println("result：\n"+result);
    }

    @Test
    public void query05(){
        Dept result=sqlSession.selectOne("zhtt.parameter.DeptMapper.query05",1);
        System.out.println("result："+result);
    }

    @Test
    public void query06(){
        List<Dept> result=sqlSession.selectList("zhtt.parameter.DeptMapper.query06","b");
        System.out.println("result：\n"+result);
    }
    @Test
    public void query07(){
        List<Dept> result=sqlSession.selectList("zhtt.parameter.DeptMapper.query07","b");
        System.out.println("result：\n"+result);
    }
    @Test
    public void query08(){
        List<Dept> result=sqlSession.selectList("zhtt.parameter.DeptMapper.query08","b");
        System.out.println("result：\n"+result);
    }
    @Test
    public void query09(){
        List<Dept> result=sqlSession.selectList("zhtt.parameter.DeptMapper.query09","b");
        System.out.println("result：\n"+result);
    }
    @Test
    public void query10(){
        DeptMapper deptMapper=sqlSession.getMapper(DeptMapper.class);
        List<Dept> result=deptMapper.query10("b",1);
        System.out.println("result：\n"+result);
    }
    @Test
    public void query11(){
        DeptMapper deptMapper=sqlSession.getMapper(DeptMapper.class);
        List<Dept> result=deptMapper.query11("b",1);
        System.out.println("result：\n"+result);
    }

    @Before
    public void init(){
        sqlSession = SessionFactoryUtil.getSqlSessionIntance();
        System.out.println("session 初始化……");
    }

    @After
    public void close(){
        if(sqlSession!=null){
            sqlSession.close();
        }
        System.out.println("session关闭……");
        System.out.printf("****** 通过这种方式调用，可以不需要mapper.java类*********");
    }
}
